﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Schema;
using System.Xml.XPath;

namespace HomeWork5
{
    class Program
    {
        static void Main(string[] args)
        {
            //1.偶数拆分为素数
            int[] prime = new int[100];
            for (int i = 2; i < 100; i++) prime[i] = 1;
            for (int i = 2; i < 100; i++)
            {
                if (prime[i] == 1)
                    for (int j = 2 * i; j < 100; j += i)
                    {
                        prime[j] = 0;
                    }
            }

            for (int i = 6; i <= 100; i += 2)
            {
                for (int j = 2; j < i; j++)
                    if (prime[j] == 1)
                        for (int k = 2; k <= i - j; k++)
                            if (prime[k] == 1 && j <= k && (j + k) == i)
                            {
                                Console.WriteLine( i+"="+ j+"+"+ k);
                                break;
                            }
            }

            //Linq排序求平均值
            int[] lin = new int[100];
            Random r = new Random();
            for (int i = 0; i < 100; i++)
            {
                lin[i] = r.Next(500);
            }

            Console.WriteLine("排序前：");
            foreach (var l in lin)
            {
                Console.WriteLine(l);
            }

            var query = from i in lin orderby i descending select i;
            Console.WriteLine("由大到小排序后:");
            foreach (var l in query)
            {
                Console.WriteLine(l);
            }

            double avg = lin.Average();
            int sum = lin.Sum();
            Console.WriteLine("和为"+ sum+ "\n平均数为"+ avg);
        }
    }
}
